﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using SFA;
using System.Configuration;

public partial class RegisterAlready : System.Web.UI.Page
{

    public string DocumentPath = ConfigurationSettings.AppSettings["ProfilePic"];
    public string ConfigReqPayString = ConfigurationSettings.AppSettings["ReqPayString"];
    public string ConfigPaymentpath = ConfigurationSettings.AppSettings["Paymentpath"];
    public string CVPath = ConfigurationSettings.AppSettings["CvPath"];
    public string strMerchantIDINR = ConfigurationSettings.AppSettings["MerchantIDINR"];
    public string strMerchantIDGBP = ConfigurationSettings.AppSettings["MerchantIDGBP"];
    public string strMerchantIDUSD = ConfigurationSettings.AppSettings["MerchantIDUSD"];

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["PayFromAdmin"] != null)
        {
            Page.MasterPageFile = "~/MasterPages/AdminMaster.master";
            Session["CandidateID"] = CommonUtility.Decrypt(Convert.ToString(Request.QueryString["CandidateID"]), true);
            Session["CandidateUserID"] = CommonUtility.Decrypt(Convert.ToString(Request.QueryString["UserID"]), true);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        txtInstrumentDate.Attributes.Add("readonly", "readonly");
        if (Convert.ToString(Page.MasterPageFile).ToUpper().Contains("/MASTERPAGES/ADMINMASTER.MASTER"))
        {
            ahrefBackLogin.Visible = false;
            hidBackBtn.Visible = false;
            hidBacktoLoginT.Visible = false;
            hidBtnBacktoLoginOff.Visible = false;
            //Session["MasterSession"] = 1;
            Session["MasterSession"] = Convert.ToString(Page.MasterPageFile).ToUpper();
        }
        else
        {
            ahrefBackLogin.Visible = true;
            hidBackBtn.Visible = true;
            hidBacktoLoginT.Visible = true;
            hidBtnBacktoLoginOff.Visible = true;
        }

        if (Session["CandidateUserID"] == null || Session["CandidateID"] == null)
        {
            Response.Redirect("loginalready.aspx");
        }

        if (!IsPostBack)
        {
            paybutton.Visible = false;
            btnAssessorPayment.Visible = false;
            Guid UserId = new Guid(Convert.ToString(Session["CandidateUserID"]));
            int cid = Convert.ToInt32(Session["CandidateID"]);
            GetCandidateDetailsDataSet(UserId, cid);
            Session["CandidateID"] = cid;
            Session["Amount"] = txtHiden.Text;
            mvwCandidateReg.ActiveViewIndex = 0;
            btnPervious.Visible = false;

            btnNext.Visible = false;
            mainMenu_MenuItemClick(sender, null);

            rdoLstPaymentMethod.Items.Clear();
            DataSet objjActMstDs = new DataSet();
            ActivityMasterBAL objActMstBAL = new ActivityMasterBAL();
            objjActMstDs = objActMstBAL.GetActivityByActivityType("PAYMENTTYPE");
            CommonUtility.BindRadioButtonList(ref rdoLstPaymentMethod, objjActMstDs, "ActivityName", "ActivityId");
            if (rdoLstPaymentMethod.Items.Count > 0)
            {
                rdoLstPaymentMethod.Items[0].Selected = true;
                //rdoLstPaymentMethod.Items[1].v = true;
                //rdoLstPaymentMethod.Items[1].Attributes.Add("style", "display='none;'");
            }
            objjActMstDs = objActMstBAL.GetActivityByActivityType("BANKPAYMENTTYPE");
            CommonUtility.BindDropDown(ref ddlPaymentMode, objjActMstDs, "ActivityName", "ActivityId");
            CommonUtility.AddSelectToDropDown(ref ddlPaymentMode);
        }
    }

    public void GetCandidateData(DataTable DtCandidateData)
    {
        string strFName = Convert.ToString(DtCandidateData.Rows[0]["FirstName"]);
        string strMName = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        string strLName = Convert.ToString(DtCandidateData.Rows[0]["LastName"]);

        string strFullName = strFName + " " + strMName + " " + strLName;
        Session["FullName"] = strFullName;

        tdAccreditationType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["AccrediationType"]);
        string strCandidateType = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        tdCandidateType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        if (strCandidateType == "Independent")
        {
            trMarketReserachCompany.Visible = false;
        }
        else
        {
            trMarketReserachCompany.Visible = true;
            tdMarketReserachCompany.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        }

        tdEmail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Email"]);
        tdRegistrationNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["RegistrationNo"]);
        tdFirstName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["FirstName"]);
        // tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        string middlename = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        if (middlename == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";
        }
        else
        {
            tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        }

        tdLastName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LastName"]);
        tdDOB.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["conDOB"]);
        string strGender = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);

        tdNationality.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["NationalityName"]);
        string contactAddress = Convert.ToString(DtCandidateData.Rows[0]["ContactAddress"]);
        if (contactAddress == "")
        { tdContectAddress.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        { tdContectAddress.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ContactAddress"]); }
        tdCountry.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CountryName"]);
        tdState.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["StateName"]);
        tdZipCode.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ZipCode"]);

        string otherphoneno = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string[] otherphonenoparts = otherphoneno.Split('-');
        if (otherphonenoparts[0] == "" || otherphonenoparts[1] == "" || otherphonenoparts[2] == "")
        { tdHomePhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdHomePhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        }

        string phoneno = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        string[] phonenoparts = phoneno.Split('-');
        if (phonenoparts[0] == "" || phonenoparts[1] == "" || phonenoparts[2] == "")
        { tdWorkPhoneNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        }
        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string mobileno = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string[] mobparts = mobileno.Split('-');
        if (mobparts[1] == "")
        { tdMobileNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
            tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        }
        //tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        //tdGraduationID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationID"]);
        tdGraduation.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationType"]);
        //tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdUniversity.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["University"]);
        //tdQualificationStatusID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatusID"]);
        tdStatus.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatus"]);
        txtStatusID.Text = Convert.ToString(DtCandidateData.Rows[0]["StatusID"]);
        hdnPanterID.Value = Convert.ToString(DtCandidateData.Rows[0]["PartnerIntID"]);
        txtAccrediationCode.Text = Convert.ToString(DtCandidateData.Rows[0]["AccrediationCode"]);

        tdProCurrentRole.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProCurrentRole"]);
        tdProExperience.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProExperience"]);
        tdProfQualitative1.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative1"]);
        tdProfQualitative2.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative2"]);
        tdProfQualitative3.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative3"]);
        tdProfQualitative4.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative4"]);


        string strProfilePath = Convert.ToString(DtCandidateData.Rows[0]["ProfilePicturePath"]);
        if (strProfilePath == "")
        {
            Image1.ImageUrl = "~/Images/Unknown2.jpg";
        }
        else
        {
            Image1.ImageUrl = DocumentPath + '/' + strProfilePath;
        }

        tdCandidateLanguageDetail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LanguageList"]);
        string strPath = string.Empty;
        string strCvTitle = Convert.ToString(DtCandidateData.Rows[0]["CVPath"]);
        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
        string strUCvpath = CVPath.Remove(0, 1);

        strPath = strAuthority + strUCvpath + strCvTitle;
        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";

        if (Convert.ToInt64(DtCandidateData.Rows[0]["PartnerIntID"]) == 0)
        {
            rdbResume1.Checked = true;
        }
        else
        {
            txtRegistrationNo.Text = Convert.ToString(DtCandidateData.Rows[0]["ParternerRegistrationNo"]);
            txtRegistrationNo.Enabled = false;

            DataSet objPartnetDs = new UserMasterBAL().GetCandidateDetailsByRegNum(txtRegistrationNo.Text);
            string strPartnerDetail = objPartnetDs.Tables[0].Rows[0]["CandidateName"].ToString();
            lblPartnetName.Text = Convert.ToString(strPartnerDetail);

            if (txtAccrediationCode.Text.Trim().ToUpper() == "CANM")
            {
                rdbResume2.Checked = true;
            }
            else if (txtAccrediationCode.Text.Trim().ToUpper() == "CANR")
            {
                rdbResume3.Checked = true;
            }
        }

        rbDiscussionGuide_CheckedChanged(null, null);
    }

    public void GetCandidatePayment(DataTable DtGetCandidatePaymentData)
    {
        DataRow drFees = DtGetCandidatePaymentData.Rows[0];
        if (Convert.ToBoolean(drFees["IsFeesPaid"]) == false)
        {
            tdFees.InnerHtml = Convert.ToString(drFees["FeesAmt"]);
            txtHiden.Text = Convert.ToString(drFees["FeesAmt"]);
            tdCurrencyType.InnerHtml = Convert.ToString(drFees["CurrencyType"]);
            tdCurrencyCode.InnerText = Convert.ToString(drFees["CurrencyCode"]);
        }
        else
        {
            trFeesPaid1.Visible = false;
            trFeesPaid2.Visible = false;
            trFeesPaid3.Visible = false;
            trFeesPaid4.Visible = false;
            trFeesPaid5.Visible = false;
        }
        if (Convert.ToBoolean(drFees["IsAssessorFeesPaid"]) == false && Convert.ToDecimal(drFees["AssessorLocalFeesAmount"]) > 0)
        {
            tdAssessorAmount.InnerHtml = Convert.ToString(drFees["AssessorLocalFeesAmount"]);
            tdAssessorCurrency.InnerHtml = Convert.ToString(drFees["AssessorCurrencyType"]);
            tdAssessorCurrencyCode.InnerText = Convert.ToString(drFees["AssessorCurrencyCode"]);
        }
        else
        {
            trAssessor1.Visible = false;
            trAssessor2.Visible = false;
            trAssessor3.Visible = false;
            trAssessor4.Visible = false;
            trAssessor5.Visible = false;
        }

    }

    public void GetCandidatePaymentDetails(DataTable DtGetCandidatePaymentDetailsData)
    {
        tdCandidateID.InnerHtml = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["CandidateID"]);
        tdPaymentAmount.InnerHtml = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["PaymentAmount"]);
        tdCurrencyTypeCompleted.InnerHtml = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["CurrencyType"]);
        tdPaymentDate.InnerHtml = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["PaymentDate"]);
        tdTxnId.InnerHtml = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["TxnId"]);
    }

    private DataSet GetCandidateDetailsDataSet(Guid Id, int cid)
    {
        DataSet objDs = null;
        try
        {
            objDs = new UserMasterBAL().GetCandidateDetails(Id, cid);

            GetCandidateData(objDs.Tables[0]);
            GetUsersCompany(objDs.Tables[1]);

            string strStatuaID = txtStatusID.Text.Trim();
            int intStatusID = Convert.ToInt32(strStatuaID);
            string strAccrediation = tdAccreditationType.InnerText.Trim();
            btnFinish.Visible = false;

            rdbResume1.Enabled = false;
            rdbResume2.Enabled = false;
            rdbResume3.Enabled = false;

            if (intStatusID == 1)
            {
                EditButton.Visible = true;
                tredittr.Visible = true;
            }
            else
            {
                EditButton.Visible = false;
                tredittr.Visible = false;
            }

            if (txtAccrediationCode.Text.Trim().ToUpper() == "CANB")
            {
                mainMenu.Items.Remove(mainMenu.Items[2]);
            }
            else
            {
                if (intStatusID == 1 || intStatusID == 23)
                {
                    mainMenu.Items.Remove(mainMenu.Items[2]);
                }
                else
                {
                    if (intStatusID == 2 & Convert.ToInt64(hdnPanterID.Value) == 0)
                    {
                        btnFinish.Visible = true;
                        rdbResume1.Enabled = true;
                        rdbResume2.Enabled = true;
                        rdbResume3.Enabled = true;
                    }

                    if (txtAccrediationCode.Text.Trim().ToUpper() == "CANM")
                    {

                        rdbResume3.Visible = false;
                    }
                    else if (txtAccrediationCode.Text.Trim().ToUpper() == "CANR")
                    {
                        rdbResume2.Visible = false;
                    }
                }
            }

            if (intStatusID == 1 || intStatusID == 2 || intStatusID == 23 || intStatusID == 3 || intStatusID == 31 || intStatusID == 26)
            {
                mainMenu.Items.Remove(mainMenu.Items[1]);
                btnNext.Visible = false;
                btnPervious.Visible = false;

            }
            else if (intStatusID == 25)
            {
                tblAccreditation.Visible = true;
                tblAccreditationPaymentDetails.Visible = false;
                btnNext.Visible = false;
                btnPervious.Visible = false;

                GetCandidatePayment(objDs.Tables[2]);
            }
            else if (intStatusID == 4)
            {
                tblAccreditation.Visible = false;
                tblAccreditationPaymentDetails.Visible = true;
                btnNext.Visible = false;
                btnPervious.Visible = false;

                GetCandidatePaymentDetails(objDs.Tables[3]);
            }


        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    private void GetUsersCompany(DataTable DtUsersCompanyData)
    {
        gvUser.DataSource = (DtUsersCompanyData);
        gvUser.DataBind();
    }

    protected void btnPervious_Click(object sender, EventArgs e)
    {
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 1:
                string strStatuaID = txtStatusID.Text.Trim();
                int intStatusID = Convert.ToInt32(strStatuaID);
                if (intStatusID == 1 || intStatusID == 2 || intStatusID == 23)
                {

                    mvwCandidateReg.ActiveViewIndex = 0;
                    btnPervious.Visible = false;
                    btnNext.Visible = false;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                }
                else
                {
                    mvwCandidateReg.ActiveViewIndex = 0;
                    btnPervious.Visible = false;
                    btnNext.Visible = false;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;

                }
                break;
            case 3:
                {

                    mvwCandidateReg.ActiveViewIndex = 0;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    btnPervious.Visible = false;
                    btnFinish.Visible = false;
                }

                break;
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 0:

                mvwCandidateReg.ActiveViewIndex = 1;
                btnPervious.Visible = false;
                btnNext.Visible = false;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                break;

        }
    }

    //Changes Done By:-VIVEK PATIL.
    protected void btnFinish_Click(object sender, EventArgs e)
    {
        //string strReturnValue;
        CandidateMasterBO objCandidateMasterBO = new CandidateMasterBO();

        UserMasterBAL objUserMasterBAL = new UserMasterBAL();

        UserMasterBO objUserMasterBO = new UserMasterBO();

        objCandidateMasterBO.SetMethod = "UPDATE";
        Guid UserId = new Guid(Convert.ToString(Session["CandidateUserID"]));
        objUserMasterBO.UserID = Convert.ToString(UserId);

        if (rdbResume1.Checked || rdbResume2.Checked || rdbResume3.Checked)
        {
            objCandidateMasterBO.CandidateID = Convert.ToInt64(Session["CandidateID"]);
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Please Select type');", true);
        }

        if (rdbResume1.Checked)
        {
            objCandidateMasterBO.RegistrationNo = "";
        }
        else if (rdbResume2.Checked || rdbResume3.Checked)
        {
            objCandidateMasterBO.RegistrationNo = Convert.ToString(txtRegistrationNo.Text.Trim());
        }

        string strreturn = (string)objUserMasterBAL.SetCandidateMasterNew(objUserMasterBO, objCandidateMasterBO);
        //objCandidateMasterBO.PartnerID";
        //objCandidateMasterBO.PartnerID = tdAccreditationType.InnerText.Trim();
        if (strreturn == "SUCCESS")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Preference Updated Successfully.');", true);
            btnFinish.Visible = false;
            rdbResume1.Enabled = false;
            rdbResume2.Enabled = false;
            rdbResume3.Enabled = false;
            txtRegistrationNo.Enabled = false;
        }
        else if (strreturn == "NOTEXIST")
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Registration No Not Exist.');", true);
        }
    }
    //

    protected void mainMenu_MenuItemClick(object sender, MenuEventArgs e)
    {
        //paybutton.Visible = false;
        int intActiveIndex;
        if (e != null)
        {
            mvwCandidateReg.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        intActiveIndex = mvwCandidateReg.ActiveViewIndex;
        string strAccrediation = tdAccreditationType.InnerText.Trim();
        if (txtAccrediationCode.Text.Trim().ToUpper() == "CANB")
        {
            switch (intActiveIndex)
            {
                case 0:
                    paybutton.Visible = false;
                    chkTermsConditions.Checked = false;
                    string strStatuaID = txtStatusID.Text.Trim();
                    int intStatusID = Convert.ToInt32(strStatuaID);
                    if (intStatusID == 1 || intStatusID == 2 || intStatusID == 23)
                    {

                        btnNext.Visible = false;

                        //mainMenu.Items.Remove(mainMenu.Items[1]);
                    }
                    else
                    {
                        btnNext.Visible = false;
                        btnPervious.Visible = false;
                    }
                    break;
            }

        }
    }


    public string getRemoteAddr()
    {
        string UserIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (UserIPAddress == null)
        {
            UserIPAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        return UserIPAddress;
    }
    public string getSecureCookie(HttpRequest Request)
    {

        HttpCookie secureCookie = Request.Cookies["vsc"];
        if (secureCookie != null)
        {
            return secureCookie.ToString();
        }
        else
        {
            return "";
        }


    }
    protected void paybutton_Click(object sender, EventArgs e)
    {
        //tdErrorPayment.InnerText = "";
        string strIsPaymentTesting = Convert.ToString(ConfigurationSettings.AppSettings["IsPaymentTesting"]);
        string cndID = Convert.ToString(Session["CandidateID"]);
        string strCurrencyType = Convert.ToString(tdCurrencyCode.InnerText);
        Session["PayCurrencyType"] = strCurrencyType;
        lblFinalPaymentTitle.Text = "Registration Payment";
        if (rdoLstPaymentMethod.SelectedItem.Text.Trim().ToLower() == "offline")
        {
            mvwCandidateReg.SetActiveView(vwTabOfflinePayment);
            lblFeesOffline.Text = tdFees.InnerHtml;
            lblCurrencyTypeOffline.Text = "( " + tdCurrencyType.InnerHtml + " )";
            return;
        }

        if (strIsPaymentTesting == "1")
        {

            Guid gudUserID = new Guid("7B98740D-D223-41E9-ACE2-8AD4FA48CD2D");
            string strReturnValue;
            PayResponseBAL objPRBal = new PayResponseBAL();
            PayResponseBO objPRBO = new PayResponseBO();
            objPRBO.SetMethod = "INSERT";
            objPRBO.PaymentID = 0;
            //string strResCode = Convert.ToInt32(oPgResp.RespCode);
            //todo
            //objPRBO.RespCode = Convert.ToInt32(oPgResp.RespCode);
            objPRBO.RespCode = 0;
            objPRBO.CandidateID = Convert.ToInt32(cndID);
            objPRBO.RespMessage = "";
            objPRBO.TxnId = "9080809809";
            objPRBO.EPGTxnId = "9080809809";
            objPRBO.AuthIdCode = "9080809809";
            objPRBO.RRN = "9080809809";
            objPRBO.CVRespCode = "9080809809";
            objPRBO.Cookie = "9080809809";
            objPRBO.FDMSScore = "9080809809";
            objPRBO.FDMSResult = "asdfasdfsdf";
            objPRBO.CreatedBy = gudUserID;
            //objPRBO.CreatedBy = CommonUtility.GetLoggedOnUserId();
            objPRBO.PaymentAmount = 10000;
            strReturnValue = (string)objPRBal.SetPayResponse(objPRBO);
        }
        else
        {
            PGResponse objPGResponse = new PGResponse();
            CustomerDetails oCustomer = new CustomerDetails();
            SessionDetail oSession = new SessionDetail();
            AirLineTransaction oAirLine = new AirLineTransaction();
            MerchanDise oMerchanDise = new MerchanDise();
            SFA.CardInfo objCardInfo = new SFA.CardInfo();
            SFA.Merchant objMerchant = new SFA.Merchant();
            ShipToAddress objShipToAddress = new ShipToAddress();
            BillToAddress oBillToAddress = new BillToAddress();
            ShipToAddress oShipToAddress = new ShipToAddress();
            MPIData objMPI = new MPIData();
            PGReserveData oPGreservData = new PGReserveData();
            Address oHomeAddress = new Address();
            Address oOfficeAddress = new Address();
            // For getting unique MerchantTxnID 
            // Only for testing purpose. 
            // In actual scenario the merchant has to pass his transactionID
            DateTime oldTime = new DateTime(1970, 01, 01, 00, 00, 00);
            DateTime currentTime = DateTime.Now;
            TimeSpan structTimespan = currentTime - oldTime;
            string lMrtTxnID = ((long)structTimespan.TotalMilliseconds).ToString();
            string strpaypath = ConfigPaymentpath + "Common/PayResponse.aspx";
            //Setting Merchant Details
            if (Convert.ToString(strCurrencyType).ToUpper() == "INDRUPEE")
            {
                objMerchant.setMerchantDetails(strMerchantIDINR, strMerchantIDINR, strMerchantIDINR, "", lMrtTxnID, "Ord123", strpaypath, "POST", "INR", "INV123", "req.Sale", txtHiden.Text, "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");
            }
            else if (Convert.ToString(strCurrencyType).ToUpper() == "BIRTISHPOUND")
            {
                objMerchant.setMerchantDetails(strMerchantIDGBP, strMerchantIDGBP, strMerchantIDGBP, "", lMrtTxnID, "Ord123", strpaypath, "POST", "GBP", "INV123", "req.Sale", txtHiden.Text, "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");
            }
            else if (Convert.ToString(strCurrencyType).ToUpper() == "USDOLLAR")
            {
                objMerchant.setMerchantDetails(strMerchantIDUSD, strMerchantIDUSD, strMerchantIDUSD, "", lMrtTxnID, "Ord123", strpaypath, "POST", "USD", "INV123", "req.Sale", txtHiden.Text, "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");
            }
            else
            {
                objMerchant.setMerchantDetails(strMerchantIDINR, strMerchantIDINR, strMerchantIDINR, "", lMrtTxnID, "Ord123", strpaypath, "POST", "INR", "INV123", "req.Sale", txtHiden.Text, "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");
            }
            //objMerchant.setMerchantDetails("00002595", "00002595", "00002595", "", lMrtTxnID, "Ord123", strpaypath, "POST", "INR", "INV123", "req.Sale", txtHiden.Text, "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");

            // Setting BillToAddress Details
            oBillToAddress.setAddressDetails("CID", "Maha Lakshmi", "Aline 1", "Aline2", "Aline3", "Pune", "MH", "48927489", "IND", "tester@opussoft.com");

            // Setting ShipToAddress Details
            oShipToAddress.setAddressDetails("$23@#|", "<script>", "Add 3", "City", "State", "443543", "IND", "tester@opussoft.com");

            //Setting MPI datails.
            //objMPI.setMPIRequestDetails ("1000","INR10.00","356","2","2 shirts","","","","0","","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");

            // Setting Name home/office Address Details 
            // Order of Parameters =>        AddLine1, AddLine2,      AddLine3,   City,   State ,  Zip,          Country, Email id
            oHomeAddress.setAddressDetails("2Sandeep", "Uttam Corner", "Chinchwad", "Pune", "state", "4385435873", "IND", "test@test.com");

            // Order of Parameters =>        AddLine1, AddLine2,      AddLine3,   City,   State ,  Zip,          Country, Email id
            oOfficeAddress.setAddressDetails("2Opus", "MayFairTowers", "Wakdewadi", "Pune", "state", "4385435873", "IND", "test@test.com");

            // Stting  Customer Details 
            // Order of Parameters =>  First Name,LastName ,Office Address Object,Home Address Object,Mobile No,RegistrationDate, flag for matching bill to address and ship to address 
            oCustomer.setCustomerDetails("Sandeep", "patil", oOfficeAddress, oHomeAddress, "9423203297", "13-06-2007", "Y");

            //Setting Merchant Dise Details 
            // Order of Parameters =>       Item Purchased,Quantity,Brand,ModelNumber,Buyers Name,flag value for matching CardName and BuyerName
            oMerchanDise.setMerchanDiseDetails("Computer", "2", "Intel", "P4", "Sandeep Patil", "Y");

            //Setting  Session Details        
            // Order of Parameters =>     Remote Address, Cookies Value            Browser Country,Browser Local Language,Browser Local Lang Variant,Browser User Agent'
            oSession.setSessionDetails(getRemoteAddr(), getSecureCookie(Request), "", Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"], "", Request.ServerVariables["HTTP_USER_AGENT"]);

            //Settingr AirLine Transaction Details  
            //Order of Parameters =>               Booking Date,FlightDate,Flight   Time,Flight Number,Passenger Name,Number Of Tickets,flag for matching card name and customer name,PNR,sector from,sector to'
            oAirLine.setAirLineTransactionDetails("10-06-2007", "22-06-2007", "13:20", "119", "Sandeep", "1", "Y", "25c", "Pune", "Mumbai");

            //SFAClient objSFAClient = new SFAClient(ConfigReqPayString);
            string SFAClientPath = Server.MapPath(ConfigReqPayString);
            SFAClient objSFAClient = new SFAClient(SFAClientPath);
            //SFAClient objSFAClient = new SFAClient("D:\\Axisvation\\AccreditationWorkflowProcess\\IQKS.AWP.Online\\Config\\");
            objPGResponse = objSFAClient.postSSL(objMPI, objMerchant, oBillToAddress, oShipToAddress, oPGreservData, oCustomer, oSession, oAirLine, oMerchanDise);
            string strresCode = objPGResponse.RespCode;
            //if (strresCode=="0")
            //{
            if (objPGResponse.RedirectionUrl != "" & objPGResponse.RedirectionUrl != null)
            {
                string strResponseURL = objPGResponse.RedirectionUrl;
                Response.Redirect(strResponseURL);
            }
            else
            {
                //tdErrorPayment.InnerText = "<b>Could not connect Payment Gateway. Please retry later.</b>";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Could not connect to Payment Gateway. Please retry later.');window.location='../Common/RegisterAlready.aspx';", true);
                //Response.Write("Response Code:" + objPGResponse.RespCode);
                //Response.Write("Response message:" + objPGResponse.RespMessage);
            }
            //}
            //else
            //{
            //    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Could not connect to Payment Gateway. Please retry later.');window.location='../Common/RegisterAlready.aspx';", true);
            //    //Server.Transfer("../Common/RegisterAlready.aspx");
            //    //Response.Redirect("../Common/RegisterAlready.aspx");
            //}


        }
    }
    protected void chkTermsConditions_CheckedChanged(object sender, EventArgs e)
    {
        if (((CheckBox)sender).ID == chkTermsConditions.ID)
        {
            if (chkTermsConditions.Checked)
            {
                paybutton.Visible = true;
                rdoLstPaymentMethod.Visible = true;
            }
            else
            {
                paybutton.Visible = false;
                rdoLstPaymentMethod.Visible = false;
            }
        }
        else if (((CheckBox)sender).ID == chkAssessorPayment.ID)
        {
            if (chkAssessorPayment.Checked)
            {
                btnAssessorPayment.Visible = true;
                rdoLstPaymentMethod.Visible = true;
            }
            else
            {
                btnAssessorPayment.Visible = false;
                rdoLstPaymentMethod.Visible = false;
            }
        }

    }
    protected void EditButton_Click(object sender, EventArgs e)
    {
        // Session["UserID"] = strUserID.Trim();
        // Session["CandidateID"] = strCandidateID.Trim();
        //if(objDs.Tables.Count>0)
        //  objDs.Clear();
        Response.Redirect("~/Common/EditRegisterdPage.aspx");
    }

    protected void btnSaveOfflinePaymentDetail_Click(object sender, EventArgs e)
    {
        PayResponseBO param = new PayResponseBO();
        double Amount = 0;
        double.TryParse(lblFeesOffline.Text, out Amount);
        param.CandidateID = Convert.ToInt32(Session["CandidateID"]);
        param.PaymentAmount = Amount;
        param.PaymentTypeId = Convert.ToInt32(rdoLstPaymentMethod.SelectedItem.Value);
        param.BankPaymentTypeId = Convert.ToInt32(ddlPaymentMode.SelectedItem.Value);
        //param.ChequeNumber = int.Parse(txtIntrumentNumber.Text);
        param.ChequeNumber = txtIntrumentNumber.Text;
        param.BankName = txtBankName.Text;
        param.BankBranch = txtBranch.Text;
        param.ChequeDate = DateTime.Parse(txtInstrumentDate.Text);
        param.Remark = txtRemark.Text;
        param.IsAssessorPayment = (lblFinalPaymentTitle.Text == "Registration Payment" ? 0 : 1);
        if (Request.QueryString.Count > 0)
        {
            param.UserId = Convert.ToString(CommonUtility.GetLoggedOnUserId());
        }
        else
        {
            param.UserId = "";

        }
        object objStatus = string.Empty;
        objStatus = new PayResponseBAL().SetPayResponseOffline(param);

        if ((string)objStatus == "SUCCESS")
        {
            Session["RedirectedFromOfflinePayment"] = 1;

            if (Request.QueryString["PayFromAdmin"] != null)
            {
                if (Request.QueryString["PayFromAdmin"] != null)
                {
                    Response.Redirect("PayResponse.aspx?PayFromAdmin=");
                }
                else
                {
                    Response.Redirect("PayResponse.aspx");
                }

            }
            else
            {
                Response.Redirect("PayResponse.aspx");
            }
        }
        else
        {
            Response.Redirect("../Error/Error.aspx");
        }
    }



    protected void ddlPaymentMode_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
    protected void rdoLstPaymentMethod_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
    //Changes Done By:-VIVEK PATIL
    protected void rbDiscussionGuide_CheckedChanged(object sender, EventArgs e)
    {
        //alone
        //research lead
        //moderator only
        if (rdbResume1.Checked == true)
        {
            trRegistrationNo.Visible = false;
        }
        if (rdbResume2.Checked == true)
        {
            trRegistrationNo.Visible = true;
        }
        else if (rdbResume3.Checked == true)
        {
            trRegistrationNo.Visible = true;
        }

    }
    //
    protected void btnAssessorPayment_Click(object sender, EventArgs e)
    {
        string cndID = Convert.ToString(Session["CandidateID"]);
        string strCurrencyType = Convert.ToString(tdAssessorCurrencyCode.InnerText);
        Session["PayCurrencyType"] = strCurrencyType;
        lblFinalPaymentTitle.Text = "Assessor Local Payment";
        if (rdoLstPaymentMethod.SelectedItem.Text.Trim().ToLower() == "offline")
        {
            mvwCandidateReg.SetActiveView(vwTabOfflinePayment);
            lblFeesOffline.Text = tdAssessorAmount.InnerHtml;
            lblCurrencyTypeOffline.Text = "( " + tdAssessorCurrency.InnerHtml + " )";
            return;
        }
    }

    protected void txtRegistrationNo_TextChanged(object sender, EventArgs e)
    {
        DataSet objPartnetDs = new UserMasterBAL().GetCandidateDetailsByRegNum(txtRegistrationNo.Text);
        if (objPartnetDs.Tables.Count > 0)
        {
            string strPartnerDetail = objPartnetDs.Tables[0].Rows[0]["CandidateName"].ToString();
            lblPartnetName.Text = Convert.ToString(strPartnerDetail);
        }
    }
}